<template>
    <div class="win-draw-lose">
        <div class="title">1X2</div>
        <div class="body">
            <div class="item" v-for="(item, index) in datas" @click="clickmatch(item)" :key="index"
                :style="getstyle(item, index)"
                :class="detailstate.matchdetail.match.ids == state.orderData?.match?.ids && state.orderData.list[item.pk_odds_key] ? 'item_active' : ''">
                <div class="name">{{ item.odds_name || item.pk_odds_name }}</div>
                <div class="value">{{ item.odd }}</div>
            </div>
        </div>
    </div>
</template>

<script setup>
const { store, state } = inject('Sell')
const { detailstore, detailstate } = inject('detailSell')
const props = defineProps({
    data: Object,
})

const datas = computed(() => {
    let a = []
    props.data.data[0].odds.forEach(item => {
        if (item.odd != 0) {
            a.push(item)
        }
    });
    return a
})

const getstyle = (item, index) => {
    let str = ''
    if (index + 1 != datas.value.length) {
        str += 'margin-right: 4px;'
    }

    str += `width: calc( 100% / ${datas.value.length} );`

    return str
}

const clickmatch = (row) => {
    store.selectMetchResult(row, detailstate.matchdetail.match)
}
</script>

<style lang="scss" scoped>
.win-draw-lose {
    width: calc(100% - 10px);
    height: 84px;
    background-color: #fafafa;
    // border: 1px solid #ebebeb;
    padding: 8px;
    display: flex;
    flex-direction: column;

    .title {
        height: 20px;
        font-size: 14px;
        font-weight: 600;
        color: #333;
    }

    .body {
        width: 100%;
        height: 40px;
        margin-top: 8px;
        display: flex;
        justify-content: space-between;

        .item {

            background-color: #fff;
            border: 1px solid #ebebeb;
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 0 12px;
            cursor: pointer;

            .name {
                color: #252a30;
                font-weight: 600;
            }

            .value {
                color: #f83e3e;
                font-weight: 600;
            }

        }

        .item:hover {
            background-color: #ecf6ff;
        }
    }
}

.item_active {
    background-color: #ecf6ff !important;
}
</style>